import global from 'global';
cc.Class({
    extends: cc.Component,

    properties: {
		beselect:cc.Node,
		qzname:cc.Label,
		_qzinfo:{default:null},//棋子信息：{sidx:221,h:0,l:3,show:1}
		_onshow:0,//0=背面向上
    },

    onLoad () {
		cc.director.once('initqz',(e)=>{//{sidx:221,h:0,l:3,show:1}
			this._qzinfo = e;
			if(e.show == 1){
				this.showme();
				cc.log('qzcell:show');
				cc.log('qzcell:initqz,e:',JSON.stringify(this._qzinfo));
			}
			
		},this);
	},
	start(){
		//
		cc.director.on('showway',(e)=>{//reselectqz
			cc.log('qzxell:showway,e:',JSON.stringify(e));
			//cc.log('qzcell:_qzinfo:',JSON.stringify(this._qzinfo));
			if(this._qzinfo.sidx != e.sidx){
				this.beselect.opacity = 0;
			}
		},this);
		cc.director.on('moveqz',(e)=>{
			if(this._qzinfo.sidx != e.sidx){
				this.beselect.opacity = 0;
			}
		},this);
	},
	//点击触发：暗子=显示棋子，明子=选择棋子
	pointme(){
		if(this._onshow == 1){
			this.selectme();
		}else{
			this.showme();
		}
		cc.log('qzcell:pointme');
	},
	showme(){
		this._onshow = 1;
		let att = global.qiziatt(this._qzinfo.sidx);
		//cc.log('qzcell:showme,att=',JSON.stringify(att));
		this.qzname.string = att.name;
		if(att.color == 1){//红棋
			this.qzname.node.color = new cc.color(180,0,0);
		}else if(att.color == 2){
			this.qzname.node.color = new cc.color(0,150,255);
		}
		//cc.log('qzcell:showme,name=',this.qzname.string);
	},
	selectme(){
		let color = parseInt(this._qzinfo.sidx/100)
		if(color == global.rolecolor){
			this.beselect.opacity = 255;
			cc.director.emit('showway',this._qzinfo);
			//cc.director.emit('reselectqz',this._qzinfo);
			cc.log('qzcell:selectme:',JSON.stringify(this._qzinfo));
		}
		
		
	}
	
    // update (dt) {},
});
